<?php


namespace App\Traits;


use Illuminate\Support\Facades\Storage;

trait ToolsTrait
{
    function storageUrl($path)
    {
        return Storage::url($path);
    }

    /**
     *  科学计数法转成数字
     *
     * @param $num
     * @param int $double 小数点保留位数 默认5位
     * @return string
     */
    function sctonum($num, $double = '')
    {
        if (false !== stripos($num, "e")) {
            $a = explode("e", strtolower($num));
            /*if ($double) {
                return bcmul($a[0], bcpow(10, $a[1], $double), $double);
            } else {
                return bcmul($a[0], bcpow(10, $a[1], abs($a[1])), abs($a[1]));
            }*/
            return number_format($num * 1, $double ?: abs($a[1]));
        } else {
            return number_format($num * 1, $double ?: 10);
        }
    }
}
